#!/usr/bin/python
# -*- coding: utf-8 -*-  
"""
@Project : hello 
@file : genner_check_sql.py
@Author : sheen
@time : 2025/5/28 17:29
@func :
"""
from com.cn.for_cdc.common.SimpleMySQLClient import SimpleMySQLClient
from com.cn.for_cdc.common.cdc_conmons import mysql_pro_connections

edp_sql = '''
select	count(DISTINCT JOB_ID) from	asw_etl_${BU}_job.XX_SCHEDULE_JOB where	STATUS=1 AND  JOB_NAME like 'edp%'	or JOB_NAME like '%CSV%'
union all
select count(DISTINCT JOB_ID) from	asw_etl_${BU}_job.XX_JOB_LOG
where STATUS = 'S' and CREATED_TIME > date_sub(CURRENT_DATE(),INTERVAL 8 hour) 
	and JOB_ID in (
	select
		JOB_ID
	from
		asw_etl_${BU}_job.XX_SCHEDULE_JOB
	where
		STATUS=1 AND  JOB_NAME like 'edp%'
		or JOB_NAME like '%CSV%') ;
    '''


adobe_sql='''
SELECT count(DISTINCT JOB_ID) from asw_etl_${BU}_job.XX_SCHEDULE_JOB where JOB_NAME like 'adobe%' and STATUS = '1'
union all
SELECT	COUNT(DISTINCT JOB_ID) from	asw_etl_${BU}_job.XX_JOB_LOG
where STATUS = 'S' and CREATED_TIME > date_sub(CURRENT_DATE(),INTERVAL 8 hour) and	JOB_ID in (
SELECT
    JOB_ID
from
    asw_etl_${BU}_job.XX_SCHEDULE_JOB
where
    JOB_NAME like 'adobe%'
    and STATUS = '1' );


'''



bu_list = ['kvn', 'kvb', 'wtctr', 'drlv', 'drlt', 'tp','tps', 'icinl', 'icibe']
for bu in bu_list:
    # sql=edp_sql.replace('${BU}',bu).replace(' ;','')
    sql=adobe_sql.replace('${BU}',bu)
    print(bu.center(100,'-'))
    print('# '+bu)
    print(sql)
    # 从配置获取参数示例
    db_configs = mysql_pro_connections[f'{bu}_pro_job']
    client = SimpleMySQLClient(**db_configs)

    client.verify_connection()

    # # 连接验证
    if client.verify_connection():
        # 查询示例
        result = client.query(sql)
        print(result)